package proyecto.testcasetool.provider.main;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.emf.edit.domain.EditingDomain;

import proyecto.testcasetool.TestcasetoolFactory;
import proyecto.testcasetool.TestcasetoolPackage;
import proyecto.testcasetool.UseCaseModel;
import proyecto.testcasetool.provider.TestcasetoolEditPlugin;

public class ActorsGhostItemProvider extends TransientUseCaseModelItemProvider {

	public ActorsGhostItemProvider(AdapterFactory adapterFactory,
			UseCaseModel model) {
		super(adapterFactory, model);
	}

	public Collection getChildrenFeatures(Object object) {
		if (childrenFeatures == null) {
			super.getChildrenFeatures(object);
			childrenFeatures
					.add(TestcasetoolPackage.Literals.USE_CASE_MODEL__ACTOR);
		}
		return childrenFeatures;
	}

	public String getText(Object object) {
		return "Actors";
	}

	protected void collectNewChildDescriptors(Collection newChildDescriptors,
			Object object) {
		super.collectNewChildDescriptors(newChildDescriptors, object);
		newChildDescriptors.add(createChildParameter(
				TestcasetoolPackage.Literals.USE_CASE_MODEL__ACTOR,
				TestcasetoolFactory.eINSTANCE.createActor()));
	}

	@Override
	public Object getImage(Object object) {
		return getResourceLocator().getImage("full/obj16/Actor");
	}

	@Override
	public ResourceLocator getResourceLocator() {
		return TestcasetoolEditPlugin.INSTANCE;
	}

	@Override
	protected Command createDragAndDropCommand(EditingDomain domain,
			Object owner, float location, int operations, int operation,
			Collection<?> collection) {
		if (new AddCommand(domain, (EObject) owner,
				TestcasetoolPackage.Literals.USE_CASE_MODEL__ACTOR, collection)
				.canExecute()) {
			return super.createDragAndDropCommand(domain, owner, location,
					operations, operation, collection);
		}
		return UnexecutableCommand.INSTANCE;
	}

}
